var Browser = {
  isCurrentTab: function(tab) {
    return tab == window.top.getBrowser().selectedTab.linkedBrowser;
  },

  getSelectedTab: function() {
    return window.top.getBrowser().selectedTab.linkedBrowser;
  },
  
  getTabForDocument: function(doc) {
    var tabIndex = window.top.getBrowser().getBrowserIndexForDocument(doc);
    return window.top.getBrowser().getBrowserAtIndex(tabIndex);
  },
  
  addPageLoadListener: function(l) {
//    window.top.getBrowser().addEventListener("load", l, true);
    var appcontent = document.getElementById("appcontent");
    TailsNS.listen(appcontent, "DOMContentLoaded", l);
  },
  
  removePageLoadListener: function(l) {
//    window.top.getBrowser().removeEventListener("load", l, true);
    var appcontent = document.getElementById("appcontent");
    TailsNS.unlisten(appcontent, "DOMContentLoaded", l);
  },
  
  addTabChangeListener: function(l) {
    $$('content').addEventListener("select", l, true);
  },
  
  removeTabChangeListener: function(l) {
    $$('content').removeEventListener("select", l, true);
  },
  
  getCurrentDocument: function() {
    return top.content.document;
  },

  $: function(node) {
    return this.getCurrentDocument().getElementById(node);
  },
  
  end: null
};
